package io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class CopyDemo2 {
    public static void main(String[] args) throws IOException {
        FileInputStream fis =new FileInputStream("rita.jpg");//输入流
        FileOutputStream fos =new FileOutputStream("ritaMyWife.jpg");//输出流

        /*InputString超类
        */
        long start =System.currentTimeMillis();//可以避免让复制后的文件变大
        byte[] data =new byte[1024*10];
        int len;
        while((len=fis.read(data))!=-1){//获取每次复制字节的长度，用len接收
            fos.write(data,0,len);//从0开始复制，复制获取长度一样的字节
        }

        long end =System.currentTimeMillis();
        System.out.println("复制完成！耗时："+(end-start)+"ms");

        fis.close();
        fos.close();



        /*long start =System.currentTimeMillis();
        byte[] data =new byte[1024*10];
        while(fis.read(data)!=-1){
        fos.write(data);
        }

        long end =System.currentTimeMillis();
        System.out.println("复制完成！耗时："+(end-start)+"ms");

        fis.close();
        fos.close();*/


    }
}
